/*
 * Project Name spring-boot-tools
 * File Name R
 * Package Name com.huxiaosu.tools.common.base
 * Create Time 2024/7/16
 * Create by name：liujie
 */
package com.huxiaosu.tools.common.base;

import com.huxiaosu.tools.common.base.extra.AbstractExpandableData;
import lombok.Data;

/**
 * Description
 *
 * @author liujie
 * @date 2024/7/16 10:34
 */
@Data
public class R<T> extends AbstractExpandableData {
    private long code = 0;
    private String msg;

    private long timestamp = System.currentTimeMillis();
    private T data;

    public R(long code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(long code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }
    public static <T> R<T> success() {
        return new R<>(0, "success", null);
    }
    public static <T> R<T> success(T data) {
        return new R<>(0, "success", data);
    }

    /**
     * 失败返回结果
     * @param errorCode 错误码
     */
    public static <T> R<T> failed(long errorCode) {
        return new R<>(errorCode, "", null);
    }
    public static <T> R<T> failed(long errorCode,String msg) {
        return new R<>(errorCode, msg, null);
    }
    public static <T> R<T> failed(String errorMsg) {
        return new R<>(-1, errorMsg, null);
    }

}